package com.example.customview

import android.animation.AnimatorSet
import android.animation.ObjectAnimator
import android.animation.TypeEvaluator
import android.graphics.PointF
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.view.View
import com.example.customview.view.ProvinceView
import com.example.customview.view.dp

class MainActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)

        val view = findViewById<View>(R.id.view)
        /*val animator = ObjectAnimator.ofFloat(view, "radius", 150.dp);
        animator.startDelay = 1000
        animator.start()*/

        /*val animator = ObjectAnimator.ofObject(view, "pointF", PointFEvaluator(), PointF(100.dp, 200.dp))
        animator.startDelay = 1000
        animator.duration = 1500
        animator.start()*/

        /*val animatorTopAngle = ObjectAnimator.ofFloat(view, "topAngle", -45f)
        val animatorBottomAngle = ObjectAnimator.ofFloat(view, "bottomAngle", 45f)
        val animatorRotateAngle = ObjectAnimator.ofFloat(view, "rotateAngle", 270f)

        animatorTopAngle.duration = 1500
        animatorBottomAngle.duration = 1500
        animatorRotateAngle.duration = 1500

        val set = AnimatorSet()
        set.playSequentially(animatorBottomAngle, animatorRotateAngle, animatorTopAngle)
        set.startDelay = 1000
        set.start()*/

        val animator = ObjectAnimator.ofObject(view, "province", ProvinceView.ProvinceEvaluator(), "澳门特别行政区")
        animator.startDelay = 1000
        animator.duration = 10000
        animator.start()
    }

    class PointFEvaluator : TypeEvaluator<PointF> {
        override fun evaluate(p0: Float, p1: PointF, p2: PointF): PointF {
            val currX = p1.x + p0 * (p2.x - p1.x)
            val currY = p1.y + p0 * (p2.y - p1.y)
            return PointF(currX, currY)
        }

    }
}

